<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{% block title %}旅行记录管理系统{% endblock %}</title>
    
    <!-- Bootstrap 5 CSS -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <!-- Bootstrap Icons -->
    <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.0/font/bootstrap-icons.css" rel="stylesheet">
    
    <!-- 加载静态文件 -->
    {% load static %}
    
    <!-- 自定义样式 -->
    <link href="{% static 'admin_panel/css/style.css' %}?v=1.2" rel="stylesheet">
    
    {% block extra_css %}{% endblock %}
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 侧边栏 -->
            <div class="col-md-3 col-lg-2 sidebar">
                <div class="position-sticky pt-3">
                    <h4 class="text-center mb-4">旅行记录管理</h4>
                    
                    <ul class="nav flex-column">
                        <li class="nav-item">
                            <a class="nav-link {% if request.resolver_match.url_name == 'admin_dashboard' %}active{% endif %}" 
                               href="{% url 'admin_panel:admin_dashboard' %}">
                                <i class="bi bi-speedometer2 me-2"></i>仪表盘
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if 'travel' in request.resolver_match.url_name %}active{% endif %}" 
                               href="{% url 'admin_panel:admin_travel_list' %}">
                                <i class="bi bi-journal-text me-2"></i>旅行记录
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if 'user' in request.resolver_match.url_name %}active{% endif %}" 
                               href="{% url 'admin_panel:admin_user_list' %}">
                                <i class="bi bi-people me-2"></i>用户管理
                            </a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link {% if 'comment' in request.resolver_match.url_name %}active{% endif %}" 
                               href="{% url 'admin_panel:admin_comment_list' %}">
                                <i class="bi bi-chat-dots me-2"></i>评论管理
                            </a>
                        </li>
                        <li class="nav-item mt-4">
                            <a class="nav-link text-danger" href="{% url 'admin_panel:admin_logout' %}">
                                <i class="bi bi-box-arrow-right me-2"></i>退出登录
                            </a>
                        </li>
                    </ul>
                </div>
            </div>

            <!-- 主内容区域 -->
            <div class="col-md-9 col-lg-10 main-content">
                <!-- 顶部导航 -->
                <nav class="navbar navbar-expand-lg navbar-light bg-white mb-4 p-3 rounded shadow-sm">
                    <div class="container-fluid">
                        <span class="navbar-brand mb-0 h1">{% block page_title %}管理后台{% endblock %}</span>
                        
                        <div class="d-flex align-items-center">
                            <span class="me-3 text-muted">
                                <i class="bi bi-person-circle me-1"></i>{{ user.username }}
                            </span>
                            <a href="{% url 'admin_panel:admin_logout' %}" class="btn btn-outline-secondary btn-sm">
                                <i class="bi bi-box-arrow-right"></i>
                            </a>
                        </div>
                    </div>
                </nav>

                <!-- 消息提示 -->
                {% if messages %}
                <div class="mb-4">
                    {% for message in messages %}
                    <div class="alert alert-{{ message.tags }} alert-dismissible fade show" role="alert">
                        {{ message }}
                        <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
                    </div>
                    {% endfor %}
                </div>
                {% endif %}

                <!-- 主要内容 -->
                {% block content %}
                {% endblock %}
            </div>
        </div>
    </div>

    <!-- Bootstrap 5 JS -->
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    
    <!-- 自定义脚本 -->
    <script>
        // 确认删除对话框
        function confirmDelete(message) {
            return confirm(message || '确定要删除吗？此操作不可恢复。');
        }
        
        // 搜索表单提交
        document.addEventListener('DOMContentLoaded', function() {
            const searchForms = document.querySelectorAll('.search-form');
            searchForms.forEach(form => {
                form.addEventListener('submit', function(e) {
                    const input = this.querySelector('input[name="q"]');
                    if (!input.value.trim()) {
                        e.preventDefault();
                    }
                });
            });
        });
    </script>
    
    {% block extra_js %}{% endblock %}
</body>
</html>
